package net.csdn.business.kanban.api.mapper;

/**
 * @ClassName KanbanMapper
 * @Description TODO
 * @Author liuzhisheng
 * @Date 2023/9/13
 **/
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.csdn.business.kanban.api.entity.KanbanView;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

@Repository
public interface KanbanViewMapper extends BaseMapper<KanbanView> {

    @Delete("delete from kanban_view where kanban_id = #{kanbanId}")
    int removeKanbanView(@Param("kanbanId") String kanbanId);

    @Select("select max(priority) as priority,max(view_number) as view_number " +
            "from kanban_view where kanban_id = #{kanbanId}")
    HashMap<String, Integer> getViewMap(@Param("kanbanId") String kanbanId);

    @Update("update kanban_view set field_display_json = JSON_ARRAY_APPEND(field_display_json, '$', JSON_OBJECT(#{fieldId} , ${isDisplay}))" +
            "where kanban_id = #{kanbanId}")
    int updateViewFieldDisplayJson(@Param("fieldId")Long fieldId,@Param("isDisplay")boolean isDisplay,@Param("kanbanId") String kanbanId);

    @Select("select max(priority) from kanban_view where kanban_id = #{kanbanId}")
    Integer maxPriority(@Param("kanbanId")String kanbanId);
}
